package com.tanhua.dubbo.server.api;

import com.alibaba.dubbo.config.annotation.Service;
import com.tanhua.dubbo.server.pojo.UserLog;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;
@Service(version = "1.0.0")
public class UserTimeApl implements UserTimeApi {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public Long queryActiveTime(Integer userId) {
        Query query=Query.query(Criteria.where("userId").is(userId).and("type").is(2))
                .with(Sort.by(Sort.Order.desc("operateDate"))).limit(1);
        String suffix = new DateTime().toString("yyyyMMdd");
        List<UserLog> userLogList = mongoTemplate.find(query, UserLog.class, "user_log_" + "20210718");
        UserLog userLog = userLogList.get(0);
        System.out.println(userLog.getOperateDate());
        return userLog.getOperateDate();
    }
}
